"""
第六条线性用例模块
测试快捷添加员工模块-合法输入全部项添加
"""

from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
# 进入crm
driver = webdriver.Chrome()
driver.implicitly_wait(10)
driver.maximize_window()
driver.get('http://192.168.1.25/crm')

'''登录'''
# 定位器
username_locator = (By.NAME, 'name')
password_locator = (By.NAME, 'password')
btn_locator = (By.NAME, "submit")

geren_btn_locator = (By.XPATH, '/html/body/div[1]/div/div/div[2]/ul[2]/li[6]/a')
zuzhijiagou_btn_locator = (By.LINK_TEXT, '组织架构')
tianjiayonghu_btn_locator = (By.LINK_TEXT, '添加用户')

tianjiayonghu_yonghuming_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/div/div[2]/form/table/tbody/tr[1]/td[2]/input')
tianjiayonghu_mima_locator = (By.ID, 'password')
tianjiayonghu_yonghuleibie_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/div/div[2]/form/table/tbody/tr[3]/td[2]/select')
tianjiayonghu_bumen_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/div/div[2]/form/table/tbody/tr[4]/td[2]/select')
tianjiayonghu_gangwei_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/div/div[2]/form/table/tbody/tr[5]/td[2]/select')

tianjiayonghu_tianjia_btn_locator =(By.XPATH,'/html/body/div[5]/div[2]/div/div/div[2]/form/table/tbody/tr[6]/td[2]/input[1]')

# 变量赋值
yonghuming_srk=driver.find_element(*username_locator)
mima_srk=driver.find_element(*password_locator)
denglu_anniu=driver.find_element(*btn_locator)


# 登录操作
yonghuming_srk.send_keys("admin")
mima_srk.send_keys('123456')
denglu_anniu.click()
# 点击进入组织架构
driver.find_element(*geren_btn_locator).click()
driver.find_element(*zuzhijiagou_btn_locator).click()
# 进入快捷添加用户界面
driver.find_element(*tianjiayonghu_btn_locator).click()
# 输入数据
sleep(2)
driver.find_element(*tianjiayonghu_yonghuming_locator).send_keys('HYL')
driver.find_element(*tianjiayonghu_mima_locator).send_keys('123')
Select(driver.find_element(*tianjiayonghu_yonghuleibie_locator)).select_by_visible_text('管理员')
Select(driver.find_element(*tianjiayonghu_bumen_locator)).select_by_index(1)
Select(driver.find_element(*tianjiayonghu_gangwei_locator)).select_by_index(0)

driver.find_element(*tianjiayonghu_tianjia_btn_locator).click()

'''清理环境'''
sleep(2)
driver.quit()